package com.tengju.data.infrastructure.repository;

import com.tengju.data.domain.model.user.ReportDealerDominationNewUserInfo;
import com.tengju.data.domain.model.user.ReportDealerDominationNewUserRepository;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.ReportDealerDominationNewUserDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.data.custom.ReportDealerDominationNewUserMapper;
import com.tengju.data.infrastructure.repository.convert.ReportDealerDominationNewUserConvert;
import com.tengju.user.domain.model.user.UserIdCode;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Repository
public class ReportDealerDominationNewUserRepositoryImpl implements ReportDealerDominationNewUserRepository {

    @Resource
    ReportDealerDominationNewUserMapper reportDealerDominationNewUserMapper;

    /***
     * 区域市场新增
     */
    @Override
    public List<ReportDealerDominationNewUserInfo> selectByIdCodeAndYear(UserIdCode userIdCode, Integer year) {
        List<ReportDealerDominationNewUserDO> doList =
                reportDealerDominationNewUserMapper.selectByIdCodeAndYear(userIdCode.getValue(),year);
        if (CollectionUtils.isEmpty(doList)) {
            return Collections.emptyList();
        }
        return doList.stream().map(ReportDealerDominationNewUserConvert::toModel)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
